package fakedata

import (
	"doctor_api_backend/config"
	"doctor_api_backend/models"
	"fmt"
	"math/rand"
	"time"

	"github.com/google/uuid"
)

// 生成病人假数据
func SeedPatientData() {
	names := []string{"张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十"}
	genders := []string{"Male", "Female"}
	addresses := []string{"北京市", "上海市", "广州市", "深圳市", "成都市", "杭州市"}
	nationalities := []string{"中国", "美国", "日本", "韩国"}
	ethnicities := []string{"汉族", "蒙古族", "回族", "藏族"}
	religions := []string{"无", "佛教", "基督教", "伊斯兰教"}
	educationLevels := []string{"高中", "本科", "硕士", "博士"}
	degrees := []string{"学士", "硕士", "博士"}
	occupationCategories := []string{"医生", "教师", "工程师", "律师", "学生"}
	workplaces := []string{"公司A", "公司B", "公司C", "公司D"}
	maritalStatuses := []string{"未婚", "已婚", "离异"}
	placesOfBirth := []string{"北京", "上海", "广州", "深圳"}
	povertyLevels := []string{"贫困", "非贫困"}
	contactPersonNames := []string{"张三", "李四", "王五"}
	hometowns := []string{"北京", "上海", "广州"}

	for i := 0; i < 100; i++ {
		patient := models.Patient{
			Name:                 names[rand.Intn(len(names))],
			Gender:               genders[rand.Intn(len(genders))],
			DateOfBirth:          time.Date(1980+rand.Intn(40), time.Month(rand.Intn(12)+1), rand.Intn(28)+1, 0, 0, 0, 0, time.UTC),
			IdentificationNumber: generateUniqueIdentificationNumber(),
			ContactPhone:         fmt.Sprintf("138%08d", rand.Intn(99999999)),
			ContactAddress:       addresses[rand.Intn(len(addresses))],
			Nationality:          nationalities[rand.Intn(len(nationalities))],
			Ethnicity:            ethnicities[rand.Intn(len(ethnicities))],
			Religion:             religions[rand.Intn(len(religions))],
			EducationLevel:       educationLevels[rand.Intn(len(educationLevels))],
			Degree:               degrees[rand.Intn(len(degrees))],
			OccupationCategory:   occupationCategories[rand.Intn(len(occupationCategories))],
			WorkplaceName:        workplaces[rand.Intn(len(workplaces))],
			WorkplacePhone:       fmt.Sprintf("138%08d", rand.Intn(99999999)),
			WorkplaceAddress:     addresses[rand.Intn(len(addresses))],
			DetailedAddress:      addresses[rand.Intn(len(addresses))],
			MaritalStatus:        maritalStatuses[rand.Intn(len(maritalStatuses))],
			PlaceOfBirth:         placesOfBirth[rand.Intn(len(placesOfBirth))],
			PlaceOfBirthDetail:   addresses[rand.Intn(len(addresses))],
			PovertyLevel:         povertyLevels[rand.Intn(len(povertyLevels))],
			ContactPersonName:    contactPersonNames[rand.Intn(len(contactPersonNames))],
			ContactPersonPhone:   fmt.Sprintf("138%08d", rand.Intn(99999999)),
			Hometown:             hometowns[rand.Intn(len(hometowns))],
		}

		config.DB.Create(&patient)
	}

	fmt.Println("100 条假 `病人`数据已成功插入数据库")
}

// 生成唯一的身份证号码
func generateUniqueIdentificationNumber() string {
	return uuid.New().String()
}
